package com.example.composeapp

import org.junit.Test

import org.junit.Assert.*
import kotlin.math.roundToInt

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun main(){
        val str = "1234a kotlin 5678 3 is 4"
        val newStr = str.replace(Regex("[0-9]+")){
//        val newStr = str.replace(Regex("[kot]")){
            "$"
        }
        println(newStr)
        println(65.423.toInt())
        println(65.923.toInt())
        println(65.483.roundToInt())
        println(65.523.roundToInt())
        println("%.2f".format(55.32698))

        "println".run(::isLong)//具名函数对象
            .run(::getS)
            .run(::println)

        "".also {

        }

        var a : String?= null
        a?.takeIf {
            it.isEmpty()
            it.isNotEmpty()
            it.isBlank()
            it.isNotBlank()
            it.isNullOrBlank()
            it.isBlank()
            it.isNullOrEmpty()
            it.isEmpty()
        }
        12.takeIf {
            it > 3
        }

        with(""){

        }

//        (Manager().getInfo().takeUnless {
//            it.isNullOrEmpty()
//            it.isNullOrBlank()
//        } ?: "空的").let { println(it) }

        //Blank会把空白的字符也算进去
            val st: String? = " "
        st.let {
            println(it?.isEmpty())
            println(it.isNullOrEmpty())
            println(it?.isNotEmpty())
            println(it?.isBlank())
            println(it.isNullOrBlank())
            println(it?.isNotBlank())
        }
    }

    private fun isLong(str: String) = str.length > 5
    private fun getS(b: Boolean) = if (b) "nihao" else "dsf"
}

class Manager{
    private var info: String? = null
    fun getInfo() = info
}